package br.ucb.controller;

import java.io.Serializable;
import java.util.List;

import br.ucb.bean.Disciplina;
import br.ucb.dao.DisciplinaDAO;
import br.ucb.util.SimpleEntityManager;

public class DisciplinaController extends GenericController implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private DisciplinaDAO disciplinaDAO;

	public DisciplinaDAO getDisciplinaDAO() {
		return disciplinaDAO;
	}
	public void setDisciplinaDAO(DisciplinaDAO disciplinaDAO) {
		this.disciplinaDAO = disciplinaDAO;
	}
	public void readyManagerAndDao() {
		setManager(new SimpleEntityManager("sacop"));
		this.disciplinaDAO = new DisciplinaDAO(getManager().getEntityManager());
		getManager().beginTransaction();
	}
	public List<Disciplina> findDisciplinas() {
		List<Disciplina> disciplinas;
		readyManagerAndDao();
		if(getProfessor() == null){
			disciplinas = this.disciplinaDAO.listar();
		}else
			disciplinas = this.disciplinaDAO.buscarRelacionado("professor.codigo", getProfessor().getCodigo());
		
		getManager().close();
		return disciplinas;
	}

}
